home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / strategy / xshisen-.001 / xshisen-~ / xshisen-1.35 / menubar.C < prev    next >
C/C++ Source or Header  |  1996-01-18  |  13KB  |  311 lines

  1. #include "components.h"
  2.  
  3. MenuBar::MenuBar(Widget parent, int radio_selection, int other_mode)
  4. {
  5.     Boolean trial_mode, gravity_mode;
  6.  
  7.     switch(other_mode) {
  8.     case 0:
  9.         trial_mode   = False;
  10.         gravity_mode = False;
  11.         break;
  12.     case 1:
  13.         trial_mode   = True;
  14.         gravity_mode = False;
  15.         break;
  16.     case 2:
  17.         trial_mode   = False;
  18.         gravity_mode = True;
  19.         break;
  20.     default:
  21.         fprintf(stderr, "Error: unknown game mode (%d)\n", other_mode);
  22.         exit(1);
  23.     }
  24. #if USE_MOTIF
  25.     XmString str[20];
  26.     char button_name[9];
  27.  
  28.     menubar = XmVaCreateSimpleMenuBar(parent, "mb",
  29.                                       XmVaCASCADEBUTTON, NULL, '\0',
  30.                                       XmVaCASCADEBUTTON, NULL, '\0',
  31.                                       XmVaCASCADEBUTTON, NULL, '\0',
  32.                                       NULL);
  33.     XtVaSetValues(menubar,
  34.                   XmNtopAttachment,   XmATTACH_FORM,
  35.                   XmNrightAttachment, XmATTACH_FORM,
  36.                   XmNleftAttachment,  XmATTACH_FORM,
  37.                   NULL);
  38.     title[0] = XmVaCreateSimplePulldownMenu(menubar,
  39.                                             "pd0", 0, (XtCallbackProc)GameCB,
  40.                                             XmVaPUSHBUTTON,  NULL, '\0', NULL, NULL,
  41.                                             XmVaPUSHBUTTON,  NULL, '\0', NULL, NULL,
  42.                                             XmVaPUSHBUTTON,  NULL, '\0', NULL, NULL,
  43.                                             XmVaSEPARATOR,
  44.                                             XmVaPUSHBUTTON,  NULL, '\0', NULL, NULL,
  45.                                             XmVaPUSHBUTTON,  NULL, '\0', NULL, NULL,
  46.                                             XmVaSEPARATOR,
  47.                                             XmVaPUSHBUTTON,  NULL, '\0', NULL, NULL,
  48.                                             XmVaSEPARATOR,
  49.                                             XmVaPUSHBUTTON,  NULL, '\0', NULL, NULL,
  50.                                             NULL);
  51.     title[1] = XmVaCreateSimplePulldownMenu(menubar,
  52.                                             "pd1", 1, (XtCallbackProc)SuppCB,
  53.                                             XmVaPUSHBUTTON, NULL, '\0', NULL, NULL,
  54.                                             XmVaPUSHBUTTON, NULL, '\0', NULL, NULL,
  55.                                             NULL);
  56.     title[2] = XmVaCreateSimplePulldownMenu(menubar,
  57.                                             "pd2", 2, (XtCallbackProc)ChangeGameCB,
  58.                                             XmVaRADIOBUTTON, NULL, '\0', NULL, NULL,
  59.                                             XmVaRADIOBUTTON, NULL, '\0', NULL, NULL,
  60.                                             XmVaRADIOBUTTON, NULL, '\0', NULL, NULL,
  61.                                             XmVaSEPARATOR,
  62.                                             XmVaCHECKBUTTON, NULL, '\0', NULL, NULL,
  63.                                             XmVaCHECKBUTTON, NULL, '\0', NULL, NULL,
  64.                                             XmNradioBehavior,  False,
  65.                                             XmNradioAlwaysOne, False,
  66.                                             NULL);
  67.     XtManageChild(menubar);
  68. #else /* USE_MOTIF */
  69.     char button_name[9];
  70.     Widget menushell0, menushell1, menushell2;
  71.     static char check_bits[] = {
  72.         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x20, 0x00, 0x20,
  73.         0x00, 0x10, 0x00, 0x18, 0x02, 0x0c, 0x04, 0x06, 0x08, 0x07, 0x98, 0x03,
  74.         0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00};
  75.  
  76.     menubar = XtVaCreateManagedWidget("mb", boxWidgetClass, parent,
  77.                                       XtNorientation, XtEhorizontal,
  78.                                       XtNtop,         XawChainTop,
  79.                                       XtNbottom,      XawChainTop,
  80.                                       XtNleft,        XawChainLeft,
  81.                                       XtNright,       XawChainLeft,
  82.                                       XtNborderWidth, 0,
  83.                                       NULL);
  84.     title[0] = XtVaCreateManagedWidget("pd0", menuButtonWidgetClass, menubar,
  85.                                        NULL);
  86.     title[1] = XtVaCreateManagedWidget("pd1", menuButtonWidgetClass, menubar,
  87.                                        NULL);
  88.     title[2] = XtVaCreateManagedWidget("pd2", menuButtonWidgetClass, menubar,
  89.                                        NULL);
  90.     menushell0 = XtVaCreatePopupShell("menu", simpleMenuWidgetClass, title[0],
  91.                                       NULL);
  92.     menushell1 = XtVaCreatePopupShell("menu", simpleMenuWidgetClass, title[1],
  93.                                       NULL);
  94.     menushell2 = XtVaCreatePopupShell("menu", simpleMenuWidgetClass, title[2],
  95.                                       NULL);
  96.     XtVaCreateManagedWidget("button_0", smeBSBObjectClass, menushell0,
  97.                             NULL);
  98.     XtVaCreateManagedWidget("button_1", smeBSBObjectClass, menushell0,
  99.                             NULL);
  100.     XtVaCreateManagedWidget("button_2", smeBSBObjectClass, menushell0,
  101.                             NULL);
  102.     XtVaCreateManagedWidget("sep_0", smeLineObjectClass, menushell0,
  103.                             NULL);
  104.     XtVaCreateManagedWidget("button_3", smeBSBObjectClass, menushell0,
  105.                             NULL);
  106.     XtVaCreateManagedWidget("button_4", smeBSBObjectClass, menushell0,
  107.                             NULL);
  108.     XtVaCreateManagedWidget("sep_1", smeLineObjectClass, menushell0,
  109.                             NULL);
  110.     XtVaCreateManagedWidget("button_5", smeBSBObjectClass, menushell0,
  111.                             NULL);
  112.     XtVaCreateManagedWidget("sep_2", smeLineObjectClass, menushell0,
  113.                             NULL);
  114.     XtVaCreateManagedWidget("button_6", smeBSBObjectClass, menushell0,
  115.                             NULL);
  116.     XtVaCreateManagedWidget("button_0", smeBSBObjectClass, menushell1,
  117.                             NULL);
  118.     XtVaCreateManagedWidget("button_1", smeBSBObjectClass, menushell1,
  119.                             NULL);
  120.     XtVaCreateManagedWidget("button_0", smeBSBObjectClass, menushell2,
  121.                             XtNleftMargin, 16,
  122.                             NULL);
  123.     XtVaCreateManagedWidget("button_1", smeBSBObjectClass, menushell2,
  124.                             XtNleftMargin, 16,
  125.                             NULL);
  126.     XtVaCreateManagedWidget("button_2", smeBSBObjectClass, menushell2,
  127.                             XtNleftMargin, 16,
  128.                             NULL);
  129.     XtVaCreateManagedWidget("sep_0", smeLineObjectClass, menushell2,
  130.                             NULL);
  131.     XtVaCreateManagedWidget("button_3", smeBSBObjectClass, menushell2,
  132.                             XtNleftMargin, 16,
  133.                             NULL);
  134.     XtVaCreateManagedWidget("button_4", smeBSBObjectClass, menushell2,
  135.                             XtNleftMargin, 16,
  136.                             NULL);
  137.     XtAddCallback(XtNameToWidget(menushell0, "button_0"), XtNcallback,
  138.                   (XtCallbackProc)GameCB, (XtPointer)0);
  139.     XtAddCallback(XtNameToWidget(menushell0, "button_1"), XtNcallback,
  140.                   (XtCallbackProc)GameCB, (XtPointer)1);
  141.     XtAddCallback(XtNameToWidget(menushell0, "button_2"), XtNcallback,
  142.                   (XtCallbackProc)GameCB, (XtPointer)2);
  143.     XtAddCallback(XtNameToWidget(menushell0, "button_3"), XtNcallback,
  144.                   (XtCallbackProc)GameCB, (XtPointer)3);
  145.     XtAddCallback(XtNameToWidget(menushell0, "button_4"), XtNcallback,
  146.                   (XtCallbackProc)GameCB, (XtPointer)4);
  147.     XtAddCallback(XtNameToWidget(menushell0, "button_5"), XtNcallback,
  148.                   (XtCallbackProc)GameCB, (XtPointer)5);
  149.     XtAddCallback(XtNameToWidget(menushell0, "button_6"), XtNcallback,
  150.                   (XtCallbackProc)GameCB, (XtPointer)6);
  151.     XtAddCallback(XtNameToWidget(menushell1, "button_0"), XtNcallback,
  152.                   (XtCallbackProc)SuppCB, (XtPointer)0);
  153.     XtAddCallback(XtNameToWidget(menushell1, "button_1"), XtNcallback,
  154.                   (XtCallbackProc)SuppCB, (XtPointer)1);
  155.     XtAddCallback(XtNameToWidget(menushell2, "button_0"), XtNcallback,
  156.                   (XtCallbackProc)ChangeGameCB, (XtPointer)0);
  157.     XtAddCallback(XtNameToWidget(menushell2, "button_1"), XtNcallback,
  158.                   (XtCallbackProc)ChangeGameCB, (XtPointer)1);
  159.     XtAddCallback(XtNameToWidget(menushell2, "button_2"), XtNcallback,
  160.                   (XtCallbackProc)ChangeGameCB, (XtPointer)2);
  161.     XtAddCallback(XtNameToWidget(menushell2, "button_3"), XtNcallback,
  162.                   (XtCallbackProc)ChangeGameCB, (XtPointer)3);
  163.     XtAddCallback(XtNameToWidget(menushell2, "button_4"), XtNcallback,
  164.                   (XtCallbackProc)ChangeGameCB, (XtPointer)4);
  165.     check = XCreateBitmapFromData(XtDisplay(menubar),
  166.                                   XRootWindowOfScreen(XtScreen(menubar)),
  167.                                   check_bits, 16, 16);
  168. #endif /* USE_MOTIF */
  169.  
  170.     // Set one item on the radio button
  171.     CheckRadio(radio_selection);
  172.     // "Restart" and "Pause" is initially disabled.
  173.     DisableRestart();
  174.     // Set the "Click Trial" check button
  175.     ClickTrial(trial_mode, gravity_mode);
  176. }
  177.  
  178. void
  179. MenuBar::DisableRestart(void)
  180. {
  181.     XtVaSetValues(XtNameToWidget(title[0], "*button_1"),
  182.                   XtNsensitive, False,
  183.                   NULL);
  184.     XtVaSetValues(XtNameToWidget(title[0], "*button_2"),
  185.                   XtNsensitive, False,
  186.                   NULL);
  187.     restart_disabled = 1;
  188. }
  189.  
  190. void
  191. MenuBar::Sensitive(void)
  192. {
  193.     XtVaSetValues(XtNameToWidget(title[1], "*button_0"),
  194.                   XtNsensitive, True,
  195.                   NULL);
  196.     XtVaSetValues(XtNameToWidget(title[1], "*button_1"),
  197.                   XtNsensitive, True,
  198.                   NULL);
  199.     if (restart_disabled) {
  200.         XtVaSetValues(XtNameToWidget(title[0], "*button_1"),
  201.                       XtNsensitive, True,
  202.                       NULL);
  203.         XtVaSetValues(XtNameToWidget(title[0], "*button_2"),
  204.                       XtNsensitive, True,
  205.                       NULL);
  206.         restart_disabled = 0;
  207.     }
  208. }
  209.  
  210. void
  211. MenuBar::Insensitive(void)
  212. {
  213.     XtVaSetValues(XtNameToWidget(title[1], "*button_0"),
  214.                   XtNsensitive, False,
  215.                   NULL);
  216.     XtVaSetValues(XtNameToWidget(title[1], "*button_1"),
  217.                   XtNsensitive, False,
  218.                   NULL);
  219. }
  220.  
  221. void
  222. MenuBar::PauseOn(void)
  223. {
  224.     XtVaSetValues(XtNameToWidget(title[0], "*button_0"),
  225.                   XtNsensitive, False,
  226.                   NULL);
  227.     XtVaSetValues(XtNameToWidget(title[0], "*button_1"),
  228.                   XtNsensitive, False,
  229.                   NULL);
  230.     Insensitive();
  231. }
  232.  
  233. void
  234. MenuBar::PauseOff(void)
  235. {
  236.     XtVaSetValues(XtNameToWidget(title[0], "*button_0"),
  237.                   XtNsensitive, True,
  238.                   NULL);
  239.     XtVaSetValues(XtNameToWidget(title[0], "*button_1"),
  240.                   XtNsensitive, True,
  241.                   NULL);
  242.     Sensitive();
  243. }
  244.  
  245. void
  246. MenuBar::ClickTrial(Boolean click, Boolean gravity)
  247. {
  248. #if USE_MOTIF
  249.     XtVaSetValues(XtNameToWidget(title[2], "*button_3"),
  250.                   XmNset, click,
  251.                   NULL);
  252.     XtVaSetValues(XtNameToWidget(title[2], "*button_4"),
  253.                   XmNset, gravity,
  254.                   NULL);
  255. #else /* USE_MOTIF */
  256.     XtVaSetValues(XtNameToWidget(title[2], "*button_3"),
  257.                   XtNleftBitmap, (click ? check : 0),
  258.                   NULL);
  259.     XtVaSetValues(XtNameToWidget(title[2], "*button_4"),
  260.                   XtNleftBitmap, (gravity ? check : 0),
  261.                   NULL);
  262. #endif /* USE_MOTIF */
  263. }
  264.  
  265. void
  266. MenuBar::DemoMode(void)
  267. {
  268.     Arg arg;
  269.  
  270.     // make only "exit" button remain active
  271.     XtSetArg(arg, XtNsensitive, False);
  272.     XtSetValues(XtNameToWidget(title[0], "*button_0"), &arg, 1);
  273.     XtSetValues(XtNameToWidget(title[0], "*button_1"), &arg, 1);
  274.     XtSetValues(XtNameToWidget(title[0], "*button_2"), &arg, 1);
  275.     XtSetValues(XtNameToWidget(title[1], "*button_0"), &arg, 1);
  276.     XtSetValues(XtNameToWidget(title[1], "*button_1"), &arg, 1);
  277. }
  278.  
  279. void
  280. MenuBar::CheckRadio(int which)
  281. {
  282.     Arg arg_off, arg_on;
  283. #if USE_MOTIF
  284.     XtSetArg(arg_off, XmNset, False);
  285.     XtSetArg(arg_on,  XmNset, True);
  286. #else /* USE_MOTIF */
  287.     /* Athena widget sets contains the 'Toggle' widget, but it
  288.        is unusable from the simple menubar widget.  I have to
  289.        get it toggled by myself. */
  290.     XtSetArg(arg_off, XtNleftBitmap, NULL);
  291.     XtSetArg(arg_on,  XtNleftBitmap, check);
  292. #endif
  293.     switch(which) {
  294.     case 0:
  295.         XtSetValues(XtNameToWidget(title[2], "*button_0"), &arg_on,  1);
  296.         XtSetValues(XtNameToWidget(title[2], "*button_1"), &arg_off, 1);
  297.         XtSetValues(XtNameToWidget(title[2], "*button_2"), &arg_off, 1);
  298.         break;
  299.     case 1:
  300.         XtSetValues(XtNameToWidget(title[2], "*button_0"), &arg_off, 1);
  301.         XtSetValues(XtNameToWidget(title[2], "*button_1"), &arg_on,  1);
  302.         XtSetValues(XtNameToWidget(title[2], "*button_2"), &arg_off, 1);
  303.         break;
  304.     case 2:
  305.         XtSetValues(XtNameToWidget(title[2], "*button_0"), &arg_off,  1);
  306.         XtSetValues(XtNameToWidget(title[2], "*button_1"), &arg_off, 1);
  307.         XtSetValues(XtNameToWidget(title[2], "*button_2"), &arg_on,  1);
  308.         break;
  309.     }
  310. }
  311.